/**
 * 作者：陈文斌 on 2019/1/8.
 * 邮箱：chen_wennbin@163.com
 * 版本：v1.0
 */

import 'package:flutter/material.dart';
import 'package:crm/constant/constant.dart';

class PromptBar extends StatefulWidget {
  /// 提示文字
  final String title;

  /// 标题后面小部件
  final Widget trailing;

  /// 关闭按钮是否可见（默认可见，false）
  final bool closeVisible;

  /// 点击关闭的回调
  final GestureTapCallback onClose;

  @override
  PromptBar({
    Key key,
    this.title,
    this.trailing,
    this.closeVisible = false,
    this.onClose,
  }) : super(key: key);

  State<StatefulWidget> createState() => _PromptBarState();
}

class _PromptBarState extends State<PromptBar> {
  bool visible = false;

  @override
  Widget build(BuildContext context) {
    return Offstage(
      offstage: visible,
      child: Container(
        width: AppScreen.setWidth(375),
        constraints: BoxConstraints(minHeight: 35),
        decoration: BoxDecoration(
          color: Color(0xFFF0F8FF),
        ),
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            Padding(padding: EdgeInsets.only(left: 20)),
            Expanded(
              child: Row(
                children: <Widget>[
                  Expanded(
                    child: Text(
                      widget.title,
                      style: TextStyle(
                        color: Color(0xFF4694FF),
                        fontSize: AppFontSizes.Font13,
                        fontFamily: AppFontFamilies.PingFangSC,
                      ),
                    ),
                  ),
                  widget.trailing ?? Container(),
                ],
              ),
            ),
            Offstage(
              offstage: widget.closeVisible,
              child: Row(
                children: <Widget>[
                  Padding(padding: EdgeInsets.only(left: 14)),
                  Container(
                    width: 20,
                    height: 20,
                    child: MaterialButton(
                      onPressed: () {
                        if (widget.onClose != null) {
                          widget.onClose();
                        }
                        visible = true;
                        setState(() {});
                      },
                      padding: EdgeInsets.all(0),
                      child: Image.asset(
                        'images/ic_delete_l.png',
                        width: 20,
                        height: 20,
                        fit: BoxFit.fill,
                      ),
                    ),
                  ),
                ],
              ),
            ),
            Padding(padding: EdgeInsets.only(right: 16)),
          ],
        ),
      ),
    );
  }
}
